<?php

namespace app\wmj\controller;

use support\Request;
use app\controller\WmjBaseController;

class SoundController
{
    protected $noNeedLogin = ['playAudio'];
    public function index(Request $request)
    {
        return response(__CLASS__);
    }
    //播放声音
    public function playAudio(Request $request){
        $app_id = $request->post('app_id','');
        if(!$app_id){
            return json(['code'=>0,'msg'=>'缺失参数app_id']);
        }
        $app_secret = $request->post('app_secret','');
        if(!$app_secret){
            return json(['code'=>0,'msg'=>'缺失参数app_secret']);
        }
        $device_sn = $request->post('device_sn','');
        if(!$device_sn){
            return json(['code'=>0,'msg'=>'缺失参数device_sn']);
        }
        $message = $request->post('message','');
        if(!$message){
            return json(['code'=>0,'msg'=>'缺失参数message']);
        }
        $inner = $request->post('inner',10);
        if(!$inner){
            return json(['code'=>0,'msg'=>'缺失参数inner']);
        }
        $WmjBase = new WmjBaseController();
        $data = [
            "device_sn" => $device_sn,
            "data" => [
                "cmd_type" => "play",
                "info" => [
                    "tts" =>$message,
                    "inner" =>$inner,//这个参数是播报开头叮咚提示音，有15种，不同场合选择不同。
                ],
            ],
        ];
        $res = $WmjBase->Request('send', $data,$app_id,$app_secret);
        return json($res);
    }
    //注册绑定
    public function regdev($device_sn,$app_id,$app_secret)
    {
        $WmjBase = new WmjBaseController();
        $res = $WmjBase->Request("register", ["device_sn" => $device_sn],$app_id,$app_secret);
        return $res;
    }


}
